const gulp = require('gulp');
const shell = require('gulp-shell');

const dest = './dist/';

gulp.task('clean', () => {
	const del = require('del');
	return del([dest, './docs/']);
});

gulp.task('compile-ts', shell.task('tsc'));

gulp.task('tslint', shell.task('tslint -p tsconfig.json'));

gulp.task('copy-files', () => {
	return gulp.src(['./package.json', 'readme.md']).pipe(gulp.dest(dest));
});

gulp.task('copy-widgets-files', () => {
	return gulp.src('./src/**/*.{json,wxml,wxss,js,d.ts}').pipe(gulp.dest(dest));
});

gulp.task('watch-ts', shell.task('tsc -w -m umd'));

gulp.task('md2html', () => {
	const markdown = require('gulp-markdown-github-style');
	return gulp.src('./doc/*.md').pipe(markdown()).pipe(gulp.dest('./docs/'));
});

gulp.task('docs', gulp.series('clean', 'md2html'));

gulp.task('default', gulp.series('clean', 'tslint', 'copy-files', 'copy-widgets-files', 'compile-ts'));
